class Animal {
    String name;
    /**String color;
    int age;*/
    public Animal(String name)
    {
        this.name = name;
    }
    public void eat() {
        System.out.println(name+"正在吃饭");
    }
}

class Dog extends Animal{
    boolean silly;
    public Dog(String name,boolean silly) {
        super(name);
        this.silly = silly;
    }

    public void eat() {
        System.out.println(name+"正在吃狗粮");
    }
}
class Cat extends Animal{
    public Cat(String name) {
        super(name);
    }
    public void eat() {
        System.out.println(name+"正在吃猫粮");
    }
}
public class Test {
    //3.作返回值：返回任意子类对象
    public static Animal func2(String name) {
        if (name.equals("旺福")) {
            return new Dog("旺福", false);
        }else if (name.equals("PerPer")) {
            return new Cat("PerPer");
        }else {
            return null;
        }
    }
    public static void main(String[] args) {
        Animal animal = func2("PerPer");
        animal.eat();
    }

    //2.方法传参：形参为父类型引用，可以接收任意子类的对象
    public static void func1(Animal animal) {
        animal.eat();
    }
    public static void main2(String[] args) {
        Dog dog = new Dog("旺福",false);
        Cat cat = new Cat("PerPer");
        func1(dog);
        func1(cat);
    }
    //1.直接赋值：子类对象赋值给父类对象
    public static void main1(String[] args) {
        Animal animal1 = new Dog("旺福",false);
        Animal animal2 = new Cat("PerPer");
        animal1.eat();
        animal2.eat();
    }
}
